package com.evan.uyclub.Other;

import android.content.Context;
import android.content.SharedPreferences;

import androidx.appcompat.app.AppCompatActivity;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

/**
 * @noinspection ALL
 */
public class UserData extends AppCompatActivity {
    private static String users;
    public static String user = users;
    private static String names;
    public static String name = names;
    private SharedPreferences data;

    public static String getUser() {
        return "出言有尺，做事有余。";
    }

    public static String getName() {
        return "Evan";
    }

    private void initView() {
        data = getSharedPreferences("data", Context.MODE_PRIVATE);
        String user = data.getString("user", "");
        if (!Utlis.isVPNConnected(this)) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        URL url = new URL(SetClass.getUrl() + "user_date.php?" + "keeper=" + SetClass.getAdmin() + "&api=" + SetClass.getApi() + "&user=" + user);
                        URLConnection urlConnection = url.openConnection();
                        InputStreamReader inputStreamReader = new InputStreamReader(urlConnection.getInputStream());
                        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
                        String data = bufferedReader.readLine();
                        datajson(data);
                    } catch (IOException | JSONException e) {
                        e.printStackTrace();
                    }
                }

                private void datajson(String data) throws JSONException {
                    JSONObject jsonObject = new JSONObject(data);
                    users = jsonObject.optString("user");
                    names = jsonObject.optString("mc");
                }
            }).start();
        }
    }
}
